package gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.List;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.*;

import main.Main;

import com.itextpdf.text.DocumentException;

import output.AutocompleteTxt;
import output.CreatePDF;
import output.CreateTxt;
import output.CsvParser;
import commandExecution.*;

public class SecondaryGui extends JFrame{
	
	
	//BUTTONS
	private JButton btn_txt;
	private JButton btn_jpg;
	private JButton btn_pdf;
	private JButton btn_mp3;
	private JButton btn_video;
	private JButton btn_torrent;
	private JButton btn_zip;
	private JButton btn_excel;
	private JButton btn_ppt;
	private JButton btn_web;
	private JButton btn_mail;
	private JButton btn_void;
	private JButton btn_cerca;
	private JButton btn_salva;
	private JButton btn_reset;
	private JButton btn_recovery;
	private JRadioButton save_files;
	private JRadioButton save_pdf;
	private JRadioButton seleziona_tutti;
	private JRadioButton deseleziona_tutti;
	private ButtonGroup group_sel;
	private ButtonGroup group_del;
	private JRadioButton sel_del;
	private JRadioButton desel_del;
	private ButtonGroup group;
	
	//ICONS
	private ImageIcon txt;
	private ImageIcon jpg;
	private ImageIcon pdf;
	private ImageIcon mp3;
	private ImageIcon video;
	private ImageIcon torrent;
	private ImageIcon excel;
	private ImageIcon zip;
	private ImageIcon ppt;
	private ImageIcon ricerca;
	private ImageIcon ricerca_lib;
	private ImageIcon pol;
	private ImageIcon web;
	private ImageIcon mail;
	private ImageIcon info;
	private ImageIcon save;
	private ImageIcon reset;
	private ImageIcon recovery;
	
	//SCROLLPANES
	private JSplitPane splitPane;
	private JSplitPane splitPane2;
	
	//OTHERS
	private JLabel lb_pol;
	private JLabel label;
	private JLabel label2;
	private Dimension d;
	private JTextField txt_r;
	private boolean waitCursorIsShowing;
	private Cursor waitCursor = new Cursor(Cursor.WAIT_CURSOR);
	private Cursor defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR);
	protected int my_hd_size;
	protected int my_files_size;
	
	//PANELS
	private JPanel panel_esempi;
	private JPanel panel_top;
	private JPanel panel_mid1;
	private JPanel panel_mid2;
	private JPanel panel_mid3;
	private JPanel panel_mid4;
	private JPanel panel_right;
	private JPanel panel_bottom;
	private JPanel panel_cont;
	private JPanel panel_chkbox;
	private JPanel panel_right2;
	private JPanel panel_right3;
	private JPanel panel_right4;
	private JPanel panel_right5;
	private JPanel panel_right1;
	private JLabel label3;
	private ImageIcon risultati;
	private JRadioButton foo;	
	
	//ARRAYLISTS
	private ArrayList<String> documents;
	private ArrayList<String> excels;
	private ArrayList<String> ppts;
	private ArrayList<String> images;
	private ArrayList<String> videos;
	private ArrayList<String> mp3s;
	private ArrayList<String> pdfs;
	private ArrayList<String> torrents;
	protected ArrayList<String> input;
	protected ArrayList<Integer> input_size  = new ArrayList<Integer>();
	protected ArrayList<String> input_libero;
	protected ArrayList<String> msgs;
	
	//ARRAYLIST SIZE
	private ArrayList<Integer> document_sizes;
	private ArrayList<Integer> excels_sizes;
	private ArrayList<Integer> ppts_sizes;
	private ArrayList<Integer> images_sizes;
	private ArrayList<Integer> videos_sizes;
	private ArrayList<Integer> mp3s_sizes;
	private ArrayList<Integer> pdfs_sizes;
	private ArrayList<Integer> torrents_sizes;
	
	//FLAG
	int flag;
	String nome_btn;
	Main m = new Main();
	AutocompleteTxt auto = new AutocompleteTxt();
	private JPanel panel_right6;
	private JPanel panel_right7;
	private Icon errorz;
	private Icon warningz;
	protected Icon infoz;
	
	
	public SecondaryGui(){
	
		d = new Dimension(50,10);
		
		
		ricerca = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/ricerca_test.png");
		label2 = new JLabel(ricerca);
		ricerca_lib = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/ricerca_libera.png");
		label = new JLabel(ricerca_lib);
		txt_r = new JTextField("Inserisci la parola da ricercare: ES. file.txt, .txt",23);
		txt_r.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				input_libero = new ArrayList<String>();
				String query =txt_r.getText();
				//TODO
			    List<String> words = auto.getData(query);
			    
			    nome_btn = "\nIl pulsante premuto e' stato: Ricerca libera\n";
			 
			    Iterator<String> iterator = words.iterator();
			    while(iterator.hasNext()) {
			        String word = (String)iterator.next();
			        input_libero.add(word);
			    }
			    
			   
			    CheckBoxList chk = new CheckBoxList(input_libero);
			    panel_chkbox.removeAll();
				panel_chkbox.revalidate();
				panel_chkbox.add(chk.sp);
				panel_right.add(panel_chkbox,BorderLayout.CENTER);
				panel_right.add(panel_right4, BorderLayout.SOUTH);
				setPreferredSize(new Dimension(700,250));
				setVisible(true);
				
				waitCursorIsShowing = false;
				setCursor(defaultCursor);
				JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
				
			}
		});
		errorz = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/error_icon.png");
		warningz = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/warning.png");
		infoz = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/info.png");
		pol = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/logoPol.png");
		lb_pol = new JLabel(pol);
		
		// button text files
		txt = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/word_logo.png");
		btn_txt = new JButton(txt);
		btn_txt.setBorderPainted(true);
		btn_txt.setToolTipText("Cerca file di testo");
		btn_txt.setPreferredSize(d);
		
		// button image files
		jpg = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/icon.png");
		btn_jpg = new JButton(jpg);
		btn_jpg.setBorderPainted(true);
		btn_jpg.setToolTipText("Cerca immagini");
		btn_jpg.setPreferredSize(d);
		
		// button pdf files
		pdf = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/pdf_logo.png");
		btn_pdf = new JButton(pdf);
		btn_pdf.setBorderPainted(true);
		btn_pdf.setToolTipText("Cerca PDF");
		btn_pdf.setPreferredSize(d);
		
		// button mp3 files
		mp3 = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/mp3_icon.png");
		btn_mp3 = new JButton(mp3);
		btn_mp3.setBorderPainted(true);
		btn_mp3.setToolTipText("Cerca MP3");
		btn_mp3.setPreferredSize(d);
		
		// button video files
		video = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/video_icon.png");
		btn_video = new JButton(video);
		btn_video.setBorderPainted(true);
		btn_video.setToolTipText("Cerca video");
		btn_video.setPreferredSize(d);
		
		// button torrent files
		torrent = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/eMule_icon.png");
		btn_torrent = new JButton(torrent);
		btn_torrent.setBorderPainted(true);
		btn_torrent.setToolTipText("Cerca torrent");
		btn_torrent.setPreferredSize(d);
		
		// button zip files
		zip = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/Zip_icon.png");
		btn_zip = new JButton(zip);
		btn_zip.setBorderPainted(true);
		btn_zip.setToolTipText("Cerca file zippati");
		btn_zip.setPreferredSize(d);
		
		// button excel files
		excel = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/excel_icon.png");
		btn_excel = new JButton(excel);
		btn_excel.setBorderPainted(true);
		btn_excel.setToolTipText("Cerca tabelle Excel");
		btn_excel.setPreferredSize(d);

		// button ppt files
		ppt = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/PowerPoint.png");
		btn_ppt = new JButton(ppt);
		btn_ppt.setBorderPainted(true);
		btn_ppt.setToolTipText("Cerca presentazioni PowerPoint");
		btn_ppt.setPreferredSize(d);
		
		// button web file
		web = new ImageIcon("img/firefox.png");
		btn_web = new JButton(web);
		btn_web.setBorderPainted(true);
		btn_web.setToolTipText("Cerca cronologia web");
		btn_web.setPreferredSize(d);
		btn_web.setEnabled(false);
		
		// button mail file
		mail = new ImageIcon("img/gmai.png");
		btn_mail = new JButton(mail);
		btn_mail.setBorderPainted(true);
		btn_mail.setToolTipText("Cerca cronologia mail");
		btn_mail.setPreferredSize(d);
		btn_mail.setEnabled(false);
		
		//info = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/info.png");
		btn_void = new JButton();
		btn_void.setBorderPainted(true);
		btn_void.setEnabled(false);
		btn_void.setPreferredSize(d);
		
		//save = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/save.png");
		btn_salva = new JButton("SALVA");
		btn_salva.setBorderPainted(true);
		btn_salva.setPreferredSize(new Dimension(30,30));
		
		//reset = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/reset.png");
		btn_reset = new JButton();
		btn_reset.setBorderPainted(false);
		btn_reset.setEnabled(false);
		btn_reset.setPreferredSize(new Dimension(30,30));
		
		
		save_files = new JRadioButton("Salva i file su hard disk esterno");
		save_files.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				btn_salva.setVisible(true);
				getDocuments(flag);
				CommandRunner runS = new CommandRunner();
				runS.runSize();
				my_hd_size = runS.getOutputSize();
				my_files_size = 0;
				for (int i : input_size) {
					my_files_size += i ;
				}
			
			}
		});
		save_pdf = new JRadioButton("Salva i risultati in pdf");
		save_pdf.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  
		    	  //TODO
		    	  btn_salva.setVisible(true);
		    	  getDocuments(flag);
		    	  getInputContext();
		    	  getName_btn();
		    	  
	      }
	    });
		
		sel_del = new JRadioButton("Sel. tutti i file cancellati");
		desel_del = new JRadioButton("Desel. tutti i file cancellati");
		
		seleziona_tutti = new JRadioButton("Seleziona tutti i file");
		seleziona_tutti.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				sel_del.setVisible(true);
				desel_del.setVisible(true);
				
			}
		});
		deseleziona_tutti = new JRadioButton("Deseleziona tutti i file");
		deseleziona_tutti.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				sel_del.setVisible(true);
				desel_del.setVisible(true);
				
			}
		});
		
		group = new ButtonGroup();
		group.add(save_files);
		group.add(save_pdf);
		
		group_sel = new ButtonGroup();
		group_sel.add(seleziona_tutti);
		group_sel.add(deseleziona_tutti);
		group_del = new ButtonGroup();
		group_del.add(sel_del);
		group_del.add(desel_del);
		
		
		
		
//-----------------------------------------BUTTON LISTENERS INIZIO-------------------------------------------------//
		
		btn_jpg.addActionListener(new CallFunctionJpg());
		btn_jpg.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		btn_txt.addActionListener(new CallFunctionTxt());
		btn_txt.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		btn_pdf.addActionListener(new CallFunctionPdf());
		btn_pdf.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		btn_ppt.addActionListener(new CallFunctionPpt());
		btn_ppt.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		btn_excel.addActionListener(new CallFunctionExcel());
		btn_excel.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		btn_mp3.addActionListener(new CallFunctionMp3());
		btn_mp3.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		btn_video.addActionListener(new CallFunctionVideo());
		btn_video.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		btn_torrent.addActionListener(new CallFunctionTorrent());
		btn_torrent.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		btn_zip.addActionListener(new CallFunctionZip());
		btn_zip.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		btn_mail.addActionListener(new CallFunctionMail());
		btn_zip.addActionListener(new ActionListener(){
		      public void actionPerformed(ActionEvent e){
		    	  if (waitCursorIsShowing){
				      // set the cursor back to the default
				      waitCursorIsShowing = false;
				      setCursor(defaultCursor);
				    }
				    else{
				      // change the cursor to the wait cursor
				      waitCursorIsShowing = true;
				      setCursor(waitCursor);
				     // setCursor(defaultCursor);
				    }  
	      }
	    });
		
		
			//btn_salva.addActionListener(new CallFunctionSavePDF());

		
			btn_salva.addActionListener(new CallFunctionSave());
	

		//btn_recovery.addActionListener(new CallFunctionRecovery());
		
		
		
//-----------------------------------------BUTTON LISTENERS FINE-------------------------------------------------//
		
//--------------------------PANNELLO SINISTRO INIZIO-----------------------------------------------------------//
		
		//TODO
		
		
		
		//PANNELO TOP
		panel_top = new JPanel();
		GridLayout lpanel_top = new GridLayout(1,2);
		panel_top.setLayout(lpanel_top);
		//panel_top.setPreferredSize(new Dimension(300,400));
		
		panel_top.add(lb_pol,BorderLayout.WEST);
		panel_top.add(label2);
		
		//PANNELLO MID1
		panel_mid1 = new JPanel();
		GridLayout lpanel_mid1 = new GridLayout(1,3);
		panel_mid1.setLayout(lpanel_mid1);
		
		panel_mid1.add(btn_txt);
		panel_mid1.add(btn_excel);
		panel_mid1.add(btn_ppt);
		
		//PANNELLO MID2
		panel_mid2 = new JPanel();
		GridLayout lpanel_mid2 = new GridLayout(1,3);
		panel_mid2.setLayout(lpanel_mid2);
		
		panel_mid2.add(btn_jpg);
		panel_mid2.add(btn_mp3);
		panel_mid2.add(btn_video);
		
		//PANNELLO MID3
		panel_mid3 = new JPanel();
		GridLayout lpanel_mid3 = new GridLayout(1,3);
		panel_mid3.setLayout(lpanel_mid3);
		
		panel_mid3.add(btn_torrent);
		panel_mid3.add(btn_zip);
		panel_mid3.add(btn_pdf);
		
		//PANNELLO MID4
		panel_mid4 = new JPanel();
		GridLayout lpanel_mid4 = new GridLayout(1,3);
		panel_mid4.setLayout(lpanel_mid4);
		//panel_mid4.setPreferredSize(new Dimension(10,50));
		
		panel_mid4.add(btn_web);
		panel_mid4.add(btn_mail);
		panel_mid4.add(btn_void);
		
		
		//PANNELLO LEFT_ALL
		JPanel left_all = new JPanel();
		GridLayout lleft_all = new GridLayout(5,0);
		left_all.setLayout(lleft_all);
		left_all.setPreferredSize(new Dimension(300,500));
		
		//PANNELLO CHECKBOX
		panel_chkbox = new JPanel();
		GridLayout lchkbox = new GridLayout(1,0);
		panel_chkbox.setLayout(lchkbox);
		
		
		left_all.add(panel_top);
		left_all.add(panel_mid1);
		left_all.add(panel_mid2);
		left_all.add(panel_mid3);
		left_all.add(panel_mid4);
		
//--------------------------PANNELLO SINISTRO FINE-----------------------------------------------------------//		
	
//--------------------------PANNELLO CENTRALE INIZIO-----------------------------------------------------------//	
		panel_right= new JPanel(); 
		GridLayout lpanel_right = new GridLayout(4,0); 
		panel_right.setLayout(lpanel_right);
		
		//PANNELLO RIGHT 1
		panel_right1 = new JPanel();
		GridLayout lpanel_right1 = new GridLayout(1,0);
		panel_right1.setLayout(lpanel_right1);
		
		risultati = new ImageIcon("/Users/giuliabiffi/Documents/workspace/JavaSearchingUtility/img/risultati.png");
		label3 = new JLabel(risultati);
		
		panel_right1.add(label3);
		
		//PANNELLO RIGHT 2
		panel_right2 = new JPanel();
		GridLayout lpanel_right2 = new GridLayout(0,1);
		panel_right2.setLayout(lpanel_right2);
		panel_right2.setPreferredSize(new Dimension(40,30));
		
		panel_right2.add(btn_salva);
		//panel_right2.add(btn_recovery);
		
		btn_salva.setVisible(false);
	
		//PANNELLO RIGHT 3
		panel_right3 = new JPanel();
		GridLayout lpanel_right3 = new GridLayout(1,3);
		panel_right3.setLayout(lpanel_right3);
		panel_right3.setPreferredSize(new Dimension(40,30));
		//left_all.setPreferredSize(new Dimension(300,500));
		
		panel_right3.add(save_files);
		panel_right3.add(save_pdf);
		
		panel_right4 = new JPanel();
		GridLayout lpanel_right4 = new GridLayout(2,0);
		panel_right4.setLayout(lpanel_right4);
		panel_right4.setPreferredSize(new Dimension(100,100));
		
		panel_right4.add(panel_right3, BorderLayout.CENTER);
		panel_right4.add(panel_right2, BorderLayout.CENTER);
		
		//PANEL RIGHT 5 
		panel_right5 = new JPanel();
		GridLayout lpanel_right5 = new GridLayout(1,2);
		panel_right5.setLayout(lpanel_right5);
		panel_right5.setPreferredSize(new Dimension(30,30));
		
		panel_right5.add(seleziona_tutti);
		panel_right5.add(deseleziona_tutti);
		
		
		
		panel_right5.setVisible(false);
		
		//PANEL RIGHT 6
		panel_right6 = new JPanel();
		GridLayout lpanel_right6 = new GridLayout(1,1);
		panel_right6.setLayout(lpanel_right6);
		panel_right6.setPreferredSize(new Dimension(30,30));
		
		panel_right6.add(sel_del);
		sel_del.setVisible(false);
		panel_right6.add(desel_del);
		desel_del.setVisible(false);
		
		panel_right6.setVisible(false);
		
		//PANEL RIGHT 7
		panel_right7 = new JPanel();
		GridLayout lpanel_right7 = new GridLayout(2,0);
		panel_right7.setLayout(lpanel_right7);
		panel_right7.setPreferredSize(new Dimension(30,30));
		
		panel_right7.add(panel_right5);
		panel_right7.add(panel_right6);
		
		panel_right.add(panel_right1, BorderLayout.NORTH);
		panel_right.add(panel_right7);
		panel_right.setPreferredSize(new Dimension(700,300));
//--------------------------PANNELLO CENTRALE FINE-----------------------------------------------------------//	
	
//--------------------------PANNELLO INFERIORE INIZIO-----------------------------------------------------------//	
		panel_bottom= new JPanel(); 
		GridLayout lpanel_bottom = new GridLayout(3,0); 
		panel_bottom.setLayout(lpanel_bottom);
		panel_bottom.setPreferredSize(new Dimension(350, 150));
		
		btn_cerca = new JButton("CERCA");
		
		panel_bottom.add(label);
		panel_bottom.add(txt_r);
		panel_bottom.add(btn_cerca);
		btn_cerca.setPreferredSize(new Dimension(50, 10));
		
		panel_cont= new JPanel();
		FlowLayout lpanel_cont = new FlowLayout(FlowLayout.LEFT);
		panel_cont.setLayout(lpanel_cont);
		
		panel_cont.add(panel_bottom,BorderLayout.WEST);
		//panel_cont.add(panel_esempi);
		
//--------------------------PANNELLO INFERIORE FINE-----------------------------------------------------------//	
		
//--------------------------SPLITPANES-----------------------------------------------------------------------//
		
		splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,left_all, panel_right);
		splitPane.setOneTouchExpandable(true);
		
		
		splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,splitPane,panel_cont);
		splitPane2.setOneTouchExpandable(false);
		
	
		getContentPane().add(splitPane,BorderLayout.WEST);
		getContentPane().add(splitPane2,BorderLayout.SOUTH);
		setSize(new Dimension(1012,700));
		setVisible(true);
	}
	
	
//-----------------LISTENERS & FUNCTIONS INIZIO----------------------------------------------------------------//
	
	//funzione per visualizzare i .txt
	class CallFunctionTxt implements ActionListener {
		

		public void actionPerformed(ActionEvent e){
			
			
		
			try {
				CsvParser parser = new CsvParser();
				parser.parserCsv();
				parser.createCSVs();
				CheckBoxList chk = new CheckBoxList(parser.getCsv(1));
				//TODO
				documents = parser.getCsv(1);
				document_sizes = parser.getCsvSize(1);
				flag = 1;
				nome_btn = "\nIl pulsante premuto e' stato: Ricerca documenti\n";
				panel_chkbox.removeAll();
				panel_chkbox.revalidate();
				panel_chkbox.add(chk.sp);
				panel_right.add(panel_chkbox,BorderLayout.CENTER);
				panel_right.add(panel_right4, BorderLayout.SOUTH);
				panel_right5.setVisible(true);
				panel_right6.setVisible(true);
				setPreferredSize(new Dimension(700,250));
				setVisible(true);
				
			} catch (FileNotFoundException e1) {
				System.out.println("The error is: "+ e1);
			}
			 
			
			
			 waitCursorIsShowing = false;
			 setCursor(defaultCursor);
			 JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
			
			
		}
	}
	
	//funzione per visualizzare i .jpg
	class CallFunctionJpg implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			try {
				CsvParser parser = new CsvParser();
				parser.parserCsv();
				parser.createCSVs();
				CheckBoxList chk = new CheckBoxList(parser.getCsv(2));
				/*panel_chkbox = new JPanel();
				GridLayout lchkbox = new GridLayout(1,0);
				panel_chkbox.setLayout(lchkbox);*/
				images = parser.getCsv(2);
				images_sizes = parser.getCsvSize(2);
				flag = 2;
				nome_btn = "\nIl pulsante premuto e' stato: Ricerca immagini\n";
				panel_chkbox.removeAll();
				panel_chkbox.revalidate();
				panel_chkbox.add(chk.sp);
				panel_right.add(panel_chkbox,BorderLayout.CENTER);
				panel_right.add(panel_right4, BorderLayout.SOUTH);
				panel_right5.setVisible(true);
				panel_right6.setVisible(true);
				setPreferredSize(new Dimension(700,250));
				setVisible(true);
				
			} catch (FileNotFoundException e1) {
				System.out.println("The error is: "+ e1);
			}
			 
			
			 waitCursorIsShowing = false;
			 setCursor(defaultCursor);
			 JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
		}
	}
	
	//funzione per visualizzare i .pdf
	class CallFunctionPdf implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			try {
				CsvParser parser = new CsvParser();
				parser.parserCsv();
				parser.createCSVs();
				CheckBoxList chk = new CheckBoxList(parser.getCsv(7));
				/*panel_chkbox = new JPanel();
				GridLayout lchkbox = new GridLayout(1,0);
				panel_chkbox.setLayout(lchkbox);*/
				pdfs = parser.getCsv(7);
				pdfs_sizes = parser.getCsvSize(7);
				flag = 7;
				nome_btn = "\nIl pulsante premuto e' stato: Ricerca PDF\n";
				panel_chkbox.removeAll();
				panel_chkbox.revalidate();
				panel_chkbox.add(chk.sp);
				panel_right.add(panel_chkbox,BorderLayout.CENTER);
				panel_right.add(panel_right4, BorderLayout.SOUTH);
				panel_right5.setVisible(true);
				panel_right6.setVisible(true);
				setPreferredSize(new Dimension(700,250));
				setVisible(true);
				
			} catch (FileNotFoundException e1) {
				System.out.println("The error is: "+ e1);
			}
			
			waitCursorIsShowing = false;
			setCursor(defaultCursor);
			JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
		}
	}
	
	//funzione per visualizzare excel
	class CallFunctionExcel implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			try {
				CsvParser parser = new CsvParser();
				parser.parserCsv();
				parser.createCSVs();
				CheckBoxList chk = new CheckBoxList(parser.getCsv(3));
				/*panel_chkbox = new JPanel();
				GridLayout lchkbox = new GridLayout(1,0);
				panel_chkbox.setLayout(lchkbox);*/
				excels = parser.getCsv(3);
				excels_sizes = parser.getCsvSize(3);
				flag = 3;
				nome_btn = "\nIl pulsante premuto e' stato: Ricerca file Excel\n";
				panel_chkbox.removeAll();
				panel_chkbox.revalidate();
				panel_chkbox.add(chk.sp);
				panel_right.add(panel_chkbox,BorderLayout.CENTER);
				panel_right.add(panel_right4, BorderLayout.SOUTH);
				panel_right5.setVisible(true);
				panel_right6.setVisible(true);
				setPreferredSize(new Dimension(700,250));
				setVisible(true);
				
			} catch (FileNotFoundException e1) {
				System.out.println("The error is: "+ e1);
			}
			
			waitCursorIsShowing = false;
			setCursor(defaultCursor);
			JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
		}
	}
	
	//funzione per visualizzare presentazioni
	class CallFunctionPpt implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			try {
				CsvParser parser = new CsvParser();
				parser.parserCsv();
				parser.createCSVs();
				CheckBoxList chk = new CheckBoxList(parser.getCsv(4));
				/*panel_chkbox = new JPanel();
				GridLayout lchkbox = new GridLayout(1,0);
				panel_chkbox.setLayout(lchkbox);*/
				ppts = parser.getCsv(4);
				ppts_sizes = parser.getCsvSize(4);
				flag = 4;
				nome_btn = "\nIl pulsante premuto e' stato: Ricerca presentazioni\n";
				panel_chkbox.removeAll();
				panel_chkbox.revalidate();
				panel_chkbox.add(chk.sp);
				panel_right.add(panel_chkbox,BorderLayout.CENTER);
				panel_right.add(panel_right4, BorderLayout.SOUTH);
				panel_right5.setVisible(true);
				panel_right6.setVisible(true);
				setPreferredSize(new Dimension(700,250));
				setVisible(true);
				
			} catch (FileNotFoundException e1) {
				System.out.println("The error is: "+ e1);
			}
			
			waitCursorIsShowing = false;
			setCursor(defaultCursor);
			JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
		}
	}
	
	//funzione per visualizzare video
	class CallFunctionVideo implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			try {
				CsvParser parser = new CsvParser();
				parser.parserCsv();
				parser.createCSVs();
				CheckBoxList chk = new CheckBoxList(parser.getCsv(5));
				/*panel_chkbox = new JPanel();
				GridLayout lchkbox = new GridLayout(1,0);
				panel_chkbox.setLayout(lchkbox);*/
				videos = parser.getCsv(5);
				videos_sizes = parser.getCsvSize(5);
				flag = 5;
				nome_btn = "\nIl pulsante premuto e' stato: Ricerca video\n";
				panel_chkbox.removeAll();
				panel_chkbox.revalidate();
				panel_chkbox.add(chk.sp);
				panel_right.add(panel_chkbox,BorderLayout.CENTER);
				panel_right.add(panel_right4, BorderLayout.SOUTH);
				panel_right5.setVisible(true);
				panel_right6.setVisible(true);
				setPreferredSize(new Dimension(700,250));
				setVisible(true);
				
			} catch (FileNotFoundException e1) {
				System.out.println("The error is: "+ e1);
			}
			
			waitCursorIsShowing = false;
			setCursor(defaultCursor);
			JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
		}
	}
	
	//funzione per visualizzare mp3
	class CallFunctionMp3 implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			try {
				CsvParser parser = new CsvParser();
				parser.parserCsv();
				parser.createCSVs();
				CheckBoxList chk = new CheckBoxList(parser.getCsv(8));
				/*panel_chkbox = new JPanel();
				GridLayout lchkbox = new GridLayout(1,0);
				panel_chkbox.setLayout(lchkbox);*/
				mp3s = parser.getCsv(8);
				mp3s_sizes = parser.getCsvSize(8);
				flag = 8;
				nome_btn = "\nIl pulsante premuto e' stato: Ricerca Mp3\n";
				panel_chkbox.removeAll();
				panel_chkbox.revalidate();
				panel_chkbox.add(chk.sp);
				panel_right.add(panel_chkbox,BorderLayout.CENTER);
				panel_right.add(panel_right4, BorderLayout.SOUTH);
				panel_right5.setVisible(true);
				panel_right6.setVisible(true);
				setPreferredSize(new Dimension(700,250));
				setVisible(true);
				
			} catch (FileNotFoundException e1) {
				System.out.println("The error is: "+ e1);
			}
			
			waitCursorIsShowing = false;
			setCursor(defaultCursor);
			JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
		}
	}
	
	//funzione per visualizzare torrent
	class CallFunctionTorrent implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			try {
				CsvParser parser = new CsvParser();
				parser.parserCsv();
				parser.createCSVs();
				CheckBoxList chk = new CheckBoxList(parser.getCsv(6));
				/*panel_chkbox = new JPanel();
				GridLayout lchkbox = new GridLayout(1,0);
				panel_chkbox.setLayout(lchkbox);*/
				torrents = parser.getCsv(6);
				torrents_sizes = parser.getCsvSize(6);
				flag = 6;
				nome_btn = "\nIl pulsante premuto e' stato: Ricerca torrent\n";
				panel_chkbox.removeAll();
				panel_chkbox.revalidate();
				panel_chkbox.add(chk.sp);
				panel_right.add(panel_chkbox,BorderLayout.CENTER);
				panel_right.add(panel_right4, BorderLayout.SOUTH);
				panel_right5.setVisible(true);
				panel_right6.setVisible(true);
				setPreferredSize(new Dimension(700,250));
				setVisible(true);
				
			} catch (FileNotFoundException e1) {
				System.out.println("The error is: "+ e1);
			}
			
			waitCursorIsShowing = false;
			setCursor(defaultCursor);
			JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
		}
	}
	
	class CallFunctionMail implements ActionListener{
		public void actionPerformed(ActionEvent arg0) {
		}
	}
			
	
	//funzione per visualizzare html
	class CallFunctionWeb implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			String path = "/Users/giuliabiffi";
			String[] fileTypes = {"html", "htm", "xhtml", "php", "asp"};
			
			CommandRunner.runFind(path, fileTypes);
			
			waitCursorIsShowing = false;
			setCursor(defaultCursor);
			JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE);
		}
	}
	
	//funzione per visualizzare zip
	class CallFunctionZip implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			String path = "/Users/giuliabiffi";
			String[] fileTypes = {"zip", "rar", "tar", "tar.gz"};
			
			CommandRunner.runFind(path, fileTypes);
			
			waitCursorIsShowing = false;
			setCursor(defaultCursor);
			JOptionPane.showMessageDialog(null, "Ricerca finita.", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
		}
	}
		
	//TODO
	//funzione salva
	class CallFunctionSave implements ActionListener{
		public void actionPerformed(ActionEvent e){
			if(save_pdf.isSelected()){
				if(nome_btn.equals("\nIl pulsante premuto e' stato: Ricerca libera\n")){
					input = getInputLibero();
				}
				text.createT(nome_btn,input);
				Object opz[]={"SI","NO"};
				int answer = JOptionPane.showOptionDialog(null, "Vuoi andare avanti con la ricerca?\nPremi SI per andare avanti oppure NO per terminare la ricerca e salvare i risultati su PDF", "Scelta", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, infoz, opz, opz[0]);
				
				if(answer == 1){
					//CreatePDF pdf = new CreatePDF();
					the_pdf.create(m.getInput());
					JOptionPane.showMessageDialog(null, "I file sono stati salvati su PDF.\n", "Messaggio",JOptionPane.WARNING_MESSAGE,warningz);
				}
				
			}else if(save_files.isSelected()){
				//TODO
				if(my_files_size > my_hd_size){
					JOptionPane.showMessageDialog(null, "Lo spazio sull'harddisk esterno e` insufficiente per salvare i dati!\nPer effettuare un nuovo salvataggio prego liberare spazio sul disco di analisi", "Messaggio", JOptionPane.ERROR_MESSAGE, errorz);
				}else{
					Object opz2[]={"SI","NO"};
					int answer2 = JOptionPane.showOptionDialog(null, "Spazio occupato dai file: "+(my_files_size)+" Bytes\nspazio disponibile sull'HD: "+my_hd_size+" Bytes.\n"+"Vuoi salvare?", "Messaggio",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, infoz, opz2, opz2[0]);
					if(answer2 == 0){
						String str = JOptionPane.showInputDialog(null, "Inserisci la data corrente \nes.01/01/01");
						CommandRunner.run_mkdir("/User/giuliabiffi/Desktop", "risultato_ispezione_del_" + str);
						CommandRunner.runCopy((String[])input.toArray(), "/User/giuliabiffi/Desktop/risultato_ispezione_del_" + str);
					}
				}
			}else{
				
			}
		}
	}
	
	
	//funzione per fare il recovery dei dati
	class CallFunctionRecovery implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			//TODO
		}
	}
	
	
	//-----------------LISTENERS & FUNCTIONS FINE----------------------------------------------------------------//

	//---------------TXT-------------//
	
	CreateTxt text = new CreateTxt();
	CreatePDF the_pdf = new CreatePDF();
	
	//-----------------GETTERS & SETTERS INIZIO-----------------------------------------------------------------//
	//TODO
		public void getDocuments(int n) {
			System.out.println("ci siamo o no???");
			switch (n) {
			case 1: input = documents;
					input_size = document_sizes;
					break;
			case 2: input = images;
					input_size = images_sizes;
					break;
			case 3: input = excels;
					input_size = excels_sizes;
					break;
			case 4: input = ppts;
					input_size = ppts_sizes;
					break;
			case 5: input = videos;
					input_size = videos_sizes;
					break;
			case 6: input = torrents;
					input_size = torrents_sizes;
					break;
			case 7: input = pdfs;
					input_size = pdfs_sizes;
					break;
			case 8: input = mp3s;
					input_size = mp3s_sizes;
					break;
			case 9: input = msgs;
					break;
				
			default:
					break;
			}	
		}
		
		public ArrayList<String> getInput(){
			return input;
		}
		
		public ArrayList<String> getInputLibero(){
			return input_libero;
		}
		
		public ArrayList<Integer> getInputSize(){
			for (int input : input_size) {
				System.out.println("elemento: " + input);
			}
			return input_size;
		}
		
		public String getName_btn(){
			return nome_btn;
		}
	
	//-----------------GETTERS & SETTERS FINE-----------------------------------------------------------------//
	

}
